#include "GameEngine.h"

GameEngine::GameEngine(): m_screen(NULL)
{
	//Start SDL
    SDL_Init( SDL_INIT_EVERYTHING );

    //Set up screen
    m_screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );

   //Update the screen
    SDL_Flip( m_screen );
   
}

GameEngine::~GameEngine()
{
	delete m_screen;
}

void GameEngine::run() 
{
	LevelManager level1(m_screen);
	gameLoop(level1);

}

void GameEngine::gameLoop(LevelManager& levelManager)
{
	bool isRunning = true;
	SDL_Event event;

	while(isRunning) {

		//While there's events to handle
        while( SDL_PollEvent( &event ) )
        {
			switch(event.type) {
				case SDL_QUIT:
					isRunning = false;
				break;

				case SDL_MOUSEBUTTONDOWN:
					printf("mouse button pressed\n");
				break;

				case SDL_KEYDOWN:
				
					if(event.key.keysym.sym == SDLK_RIGHT){
						printf("right key pressed\n");
					
					}
					if(event.key.keysym.sym == SDLK_LEFT) {
						printf("left key pressed\n");
					}
					if(event.key.keysym.sym == SDLK_UP) {
						printf("up key pressed\n");
					}
					if(event.key.keysym.sym == SDLK_DOWN){
						printf("down key pressed\n");
					}

				break;

				default:
				break;
			}
	
        }
		//double buffering -> flip buffers
		SDL_Flip(m_screen);
	}
}